package cn.fourhundredandeighteen.utill;

import cn.fourhundredandeighteen.UserInfo;
import cn.fourhundredandeighteen.dao.AdminDao;
import cn.fourhundredandeighteen.dao.StudentDao;
import cn.fourhundredandeighteen.dao.TeacherDao;
import cn.fourhundredandeighteen.entity.Admin;
import cn.fourhundredandeighteen.entity.Student;
import cn.fourhundredandeighteen.entity.Teacher;

/**
 * @description:
 * @author: liuyongqi
 * @time: 2020/12/24
 */
public class AdminCheck {
    public static boolean adminCheck() {
        AdminDao adminDao = MysqlConnect.into().getMapper(AdminDao.class);
        try {
            Admin admin = adminDao.selectByPrimaryKey(UserInfo.Session);
            MysqlConnect.destroy();
            if (admin != null)
                return true;
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean teacherCheck() {
        TeacherDao teacherDao = MysqlConnect.into().getMapper(TeacherDao.class);
        try {
            Teacher teacher = teacherDao.selectByPrimaryKey(UserInfo.Session);
            MysqlConnect.destroy();
            if (teacher != null)
                return true;
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean studentCheck() {
        StudentDao studentDao = MysqlConnect.into().getMapper(StudentDao.class);
        try {
            Student student = studentDao.selectByPrimaryKey(UserInfo.Session);
            MysqlConnect.destroy();
            if (student != null)
                return true;
            return false;
        } catch (Exception e) {
            return false;
        }
    }
}
